namespace Leey.Net.eTerm
{
    using System;
    using System.Collections;
    using System.Text;
    using System.Text.RegularExpressions;

    public class CmdResult
    {
        public AirFlights Airflights;
        public Packet CmdPacket;
        public string Data;
        private bool discardresult;
        private ArrayList hanzichars;
        public bool IsLastPacket;
        public int Lengh;
        public byte[] OrignalData;
        private StringBuilder printablechars;
        public string Sequnce;
        public bool Succeed;

        public CmdResult()
        {
            this.Sequnce = "";
            this.Data = "";
            this.OrignalData = null;
            this.Succeed = false;
            this.IsLastPacket = true;
            this.CmdPacket = null;
            this.Airflights = null;
            this.printablechars = new StringBuilder();
            this.hanzichars = new ArrayList();
            this.discardresult = false;
        }

        public CmdResult(byte[] inbyte, int length)
        {
            this.Sequnce = "";
            this.Data = "";
            this.OrignalData = null;
            this.Succeed = false;
            this.IsLastPacket = true;
            this.CmdPacket = null;
            this.Airflights = null;
            this.printablechars = new StringBuilder();
            this.hanzichars = new ArrayList();
            this.discardresult = false;
            int num = 0;
            this.OrignalData = new byte[length];
            Buffer.BlockCopy(inbyte, 0, this.OrignalData, 0, length);
            this.printablechars.Remove(0, this.printablechars.Length);
            for (int i = 11; i < length; i++)
            {
                byte num3 = inbyte[i];
                if (inbyte[i] >= 0x20)
                {
                    this.printablechars.Append(Convert.ToChar(inbyte[i]));
                    num++;
                    if (num >= 80)
                    {
                        this.printablechars.Append("\r\n");
                        num = 0;
                    }
                }
                else
                {
                    switch (inbyte[i])
                    {
                        case 1:
                        case 2:
                        case 3:
                        case 14:
                        {
                            continue;
                        }
                        case 13:
                        {
                            this.printablechars.Append(Convert.ToChar(inbyte[i]));
                            num = 0;
                            continue;
                        }
                        case 0x1b:
                        {
                            i++;
                            if (0x54 >= inbyte[i])
                            {
                                goto Label_0178;
                            }
                            continue;
                        }
                        case 0x1c:
                        {
                            this.printablechars.Append(Convert.ToChar(0x20));
                            num++;
                            continue;
                        }
                        case 0x1d:
                        {
                            this.printablechars.Append(Convert.ToChar(0x20));
                            num++;
                            continue;
                        }
                        case 30:
                        {
                            this.printablechars.Append(Convert.ToChar(30));
                            num++;
                            continue;
                        }
                    }
                }
                continue;
            Label_0178:
                if (((0x54 != inbyte[i]) && ((0x3f >= inbyte[i]) || (inbyte[i] >= 0x54))) && ((0x3f != inbyte[i]) && ((0x12 >= inbyte[i]) || (inbyte[i] >= 0x3f))))
                {
                    if (11 == inbyte[i])
                    {
                        i += 3;
                        continue;
                    }
                    if (14 == inbyte[i])
                    {
                        this.hanzichars.Clear();
                        i++;
                        while (i < length)
                        {
                            if ((inbyte[i] == 0x1b) && (inbyte[i + 1] == 15))
                            {
                                i++;
                                break;
                            }
                            this.hanzichars.Add(inbyte[i]);
                            i++;
                        }
                        if (this.hanzichars.Count > 0)
                        {
                            this.hanzichars.Insert(0, byte.Parse("27"));
                            this.hanzichars.Insert(1, byte.Parse("14"));
                            this.hanzichars.Add(byte.Parse("27"));
                            this.hanzichars.Add(byte.Parse("15"));
                            this.printablechars.Append(Encoding.Default.GetString(eTermEncode.DecodeGB2312((byte[]) this.hanzichars.ToArray(typeof(byte)))).Trim());
                        }
                    }
                }
            }
            this.Data = this.printablechars.ToString();
        }

        public string GetAvhdate()
        {
            Match match = new Regex(@"([0-9]{1,2}[A-Za-z]{3})\([A-Za-z]{3}\)").Match(this.Data);
            if (match.Success)
            {
                return match.Groups[1].ToString().Trim();
            }
            return "";
        }

        public bool DiscardResult
        {
            get
            {
                return this.discardresult;
            }
            set
            {
                this.discardresult = value;
            }
        }
    }
}
